<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class AddressRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'linkman'=>'required',
            'phone'=>'required',
            'address'=>'required',
            'area'=>function($attr,$value,$fail){
                if(!$value){
                    return $fail('请选择收货地址');
                }
                $info=explode('/',$value);
                if(count($info)!=3){
                    return $fail('请完善售后地址');
                }
                return true;
            }
        ];
    }

    public function messages()
    {
        return [
            'linkman.required'=>'联系人 不能为空',
            'phone.required'=>'电话号码 不能为空',
            'address.required'=>'详细地址 不能为空',
        ];
    }
}
